#include<bits/stdc++.h>
using namespace std;

struct node
{
	double w, v;
	bool operator < (const node &x) const
	{
		return v/w > x.v/x.w;
	}
}a[111];

int main()
{
	int k;
	cin>>k;
	while(k--)
	{
		double w;
		int n;
		cin>>w>>n;
		for(int i = 1;i <= n;i++)
			cin>>a[i].w>>a[i].v;
		sort(a+1, a+n+1);
		
		double v = 0;
		for(int i = 1;i <= n && w;i++)
		{
			if(w >= a[i].w)
			{
				w -= a[i].w;
				v += a[i].v;
			}
			else
			{
				v += w/a[i].w*a[i].v;
				w = 0;
			}
		}
		cout<<fixed<<setprecision(2)<<v<<endl;
	}
	cout<<endl;
	system("pause");
	return 0;
}

